package com.gisocn.onemap.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import butterknife.internal.Utils;
import com.gisocn.onemap.interfaces.OnItemClickListener;
import com.gisocn.onemap.model.Download;
import com.gisocn.onemap.sgzx.R;
import com.gisocn.onemap.utils.FormatSizeUtil;
import com.gisocn.onemap.widget.MyProgress;
import java.util.ArrayList;
import java.util.List;

/* loaded from: classes2.dex */
public class OfflineDownloadAdapter extends RecyclerView.Adapter<ViewHolder> {
    private Context context;
    private ArrayList<Download.NewItem> list;
    private OnItemClickListener onItemClickListener = null;

    /* loaded from: classes2.dex */
    public class ViewHolder_ViewBinding implements Unbinder {
        private ViewHolder target;

        public ViewHolder_ViewBinding(ViewHolder viewHolder, View view) {
            this.target = viewHolder;
            viewHolder.tvTitle = (TextView) Utils.findRequiredViewAsType(view, R.id.tv_title, "field 'tvTitle'", TextView.class);
            viewHolder.tvSize = (TextView) Utils.findRequiredViewAsType(view, R.id.tv_size, "field 'tvSize'", TextView.class);
            viewHolder.tvProgress = (TextView) Utils.findRequiredViewAsType(view, R.id.tv_progress, "field 'tvProgress'", TextView.class);
            viewHolder.progress = (MyProgress) Utils.findRequiredViewAsType(view, R.id.progress, "field 'progress'", MyProgress.class);
            viewHolder.tvTag = (TextView) Utils.findRequiredViewAsType(view, R.id.tv_tag, "field 'tvTag'", TextView.class);
            viewHolder.tvDownload = (TextView) Utils.findRequiredViewAsType(view, R.id.tv_download, "field 'tvDownload'", TextView.class);
        }

        @Override // butterknife.Unbinder
        public void unbind() {
            ViewHolder viewHolder = this.target;
            if (viewHolder == null) {
                throw new IllegalStateException("Bindings already cleared.");
            }
            this.target = null;
            viewHolder.tvTitle = null;
            viewHolder.tvSize = null;
            viewHolder.tvProgress = null;
            viewHolder.progress = null;
            viewHolder.tvTag = null;
            viewHolder.tvDownload = null;
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.Adapter
    public /* bridge */ /* synthetic */ void onBindViewHolder(ViewHolder viewHolder, int i, List list) {
        onBindViewHolder2(viewHolder, i, (List<Object>) list);
    }

    public OfflineDownloadAdapter(ArrayList<Download.NewItem> arrayList, Context context) {
        this.list = arrayList;
        this.context = context;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.Adapter
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        return new ViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_offline_download_old, viewGroup, false));
    }

    @Override // androidx.recyclerview.widget.RecyclerView.Adapter
    public void onBindViewHolder(ViewHolder viewHolder, final int i) {
        viewHolder.tvTitle.setText(this.list.get(i).getName());
        TextView textView = viewHolder.tvSize;
        textView.setText(FormatSizeUtil.getFormatSize(Double.parseDouble(this.list.get(i).getSize())) + "");
        viewHolder.tvDownload.setEnabled(true);
        viewHolder.tvDownload.setOnClickListener(new View.OnClickListener() { // from class: com.gisocn.onemap.ui.adapter.OfflineDownloadAdapter.1
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                if (OfflineDownloadAdapter.this.onItemClickListener != null) {
                    OfflineDownloadAdapter.this.onItemClickListener.onItemClick(view, i);
                }
            }
        });
        viewHolder.tvProgress.setText("");
        viewHolder.tvDownload.setVisibility(0);
        viewHolder.progress.setVisibility(8);
        viewHolder.tvDownload.setBackgroundResource(R.drawable.bg_primary_radius5_storck);
        viewHolder.tvDownload.setTextColor(ContextCompat.getColor(this.context, R.color.colorPrimary));
        if (this.list.get(i).getVersionDesc().equals("未下载")) {
            viewHolder.tvDownload.setText("下载");
        } else if (this.list.get(i).getVersionDesc().equals("已是最新版本")) {
            viewHolder.tvTag.setText("已是最新版本");
            viewHolder.tvDownload.setText("已完成");
            viewHolder.tvDownload.setEnabled(false);
            viewHolder.tvDownload.setBackgroundResource(R.drawable.bg_black_radius5_storck);
            viewHolder.tvDownload.setTextColor(ContextCompat.getColor(this.context, R.color.colorBgGray));
        } else if (this.list.get(i).getVersionDesc().equals("有更新版本")) {
            viewHolder.tvDownload.setText("更新");
            viewHolder.tvTag.setText("有更新版本");
        } else if (this.list.get(i).getVersionDesc().equals("未完成")) {
            viewHolder.tvDownload.setText("下载");
            viewHolder.tvProgress.setText("");
            viewHolder.progress.setVisibility(0);
            viewHolder.progress.setProgress(0);
        }
        TextView textView2 = viewHolder.tvTag;
        textView2.setText(this.list.get(i).getVersionDesc() + "");
        viewHolder.tvProgress.setText("");
        viewHolder.progress.setProgress(0);
    }

    /* renamed from: onBindViewHolder  reason: avoid collision after fix types in other method */
    public void onBindViewHolder2(ViewHolder viewHolder, int i, List<Object> list) {
        viewHolder.itemView.setTag(Integer.valueOf(i));
        if (list.isEmpty()) {
            onBindViewHolder(viewHolder, i);
        } else if (((Integer) list.get(0)).intValue() == 0) {
            TextView textView = viewHolder.tvProgress;
            textView.setText(this.list.get(i).getCurrentLength() + "%");
            viewHolder.progress.setVisibility(0);
            viewHolder.tvDownload.setVisibility(4);
            viewHolder.progress.setProgress(Integer.parseInt(this.list.get(i).getCurrentLength()));
            if (this.list.get(i).getCurrentLength().equals("100")) {
                viewHolder.tvTag.setText("已是最新版本");
                viewHolder.tvDownload.setText("已完成");
                viewHolder.tvDownload.setVisibility(0);
                viewHolder.tvProgress.setVisibility(4);
                viewHolder.progress.setVisibility(4);
                viewHolder.tvDownload.setEnabled(false);
                return;
            }
            viewHolder.tvTag.setText("下载中");
            viewHolder.tvDownload.setVisibility(4);
            viewHolder.progress.setVisibility(0);
            viewHolder.tvDownload.setEnabled(false);
            viewHolder.tvDownload.setText("下载");
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.Adapter
    public int getItemCount() {
        return this.list.size();
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes2.dex */
    public static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.progress)
        MyProgress progress;
        @BindView(R.id.tv_download)
        TextView tvDownload;
        @BindView(R.id.tv_progress)
        TextView tvProgress;
        @BindView(R.id.tv_size)
        TextView tvSize;
        @BindView(R.id.tv_tag)
        TextView tvTag;
        @BindView(R.id.tv_title)
        TextView tvTitle;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
